﻿using System;
using System.Collections.Generic;

namespace _1_11
{
    class Product
    {
        readonly string name;
        public string Name { get { return name; } }

        readonly decimal price;
        public decimal Price { get { return price; } }

        public Product(string name, decimal price)
        {
            this.name = name;
            this.price = price;
        }

        public static List<Product> GetSampleProducts()
        {
            return new List<Product>
            {
                new Product(name: "West Side Story", price: 9.99m),
                new Product(name: "Assassins", price: 14.99m),
                new Product(name: "Frogs", price: 13.99m),
                new Product(name: "Sweeny", price: 10.99m)
            };
        }

        public override string ToString()
        {
            return string.Format("{0}: {1}", name, price);
        }
    }

    class Program
    {
        static void Main_()
        {
            List<Product> products = Product.GetSampleProducts();

            Predicate<Product> test = delegate (Product p) { return p.Price > 10m; };
            List<Product> matches = products.FindAll(test);

            Action<Product> print = Console.WriteLine;
            matches.ForEach(print);
        }
    }
}
//print变量的初始化使用了C#2的另一个特性————方法组转换，它简化了从现有方法创建委托的过程。
//具体的说，它使我们可以非常轻松地更改测试条件并对每个匹配项采取单独的操作。
//涉及的委托变量（test和print）可以传递给一个方法————相同的方法可以用于测试完全不同的条件以及执行完全不同的操作